﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using FinosLibrary;
using System.Windows.Controls;
namespace FinosAdmin {
    public class AppData:NotifyProperty {
        public class AppInstance {
            public string name;
            public string log;
            public ObservableCollection<string> clients;
            public override string ToString() {
                return name;
            }
        }
        public string name { get; set; }
        public string path;
        public UserControl propertyPage;
        public ObservableCollection<AppInstance> instances { get; set; }
        public ObservableCollection<string> AppClients { get { return UI is InstanceDetail ? selection.clients : null; } set { } }
        private InstanceDetail instanceDetail;
        public string AppLog { get { return UI is InstanceDetail ? selection.log : ""; } set { } }
        private object _UI;
        public object UI {
            get { return _UI; }
            set {
                _UI = value;
                this.NotifyPropertyChanged(x => x.UI);
                if (UI is InstanceDetail) {
                    this.NotifyPropertyChanged(x => x.AppLog);
                    if (selection.clients == null) {
                        ModelLogic.doLogic("GetAppClients", name + '/' + selection.name);
                    } else {
                        this.NotifyPropertyChanged(x => x.AppClients);
                    }
                }
            }
        }
        private AppInstance _selection;
        public AppInstance selection {
            get { return _selection; }
            set {
                _selection = value;
                if (value == null) {
                    UI = "";
                } else if (value.name != "自定义属性页") {
                    if (instanceDetail == null) {
                        instanceDetail = new InstanceDetail();
                    }
                    UI = instanceDetail;
                } else {
                    ModelLogic.doLogic("GetPropertyPage", name);
                }
            }
        }
    }
}
